$(function() {
	$("#datagrid_list")
			.datagrid(
					{
						url : '/product/list.json',
						rownumbers : true,
						singleSelect : true,
						border : false,
						pagination : true,
						toolbar : '#tb',
						pageSize : 20,
						columns : [ [
								{
									field : "productId",
									title : "",
									hidden : true
								},
								{
									field : "productName",
									title : "产品名称",
									formatter : function(value, rowData,
											rowIndex) {
										return "<a href='/product/detail?id="
												+ rowData.productId
												+ "&keepThis=true&amp;TB_iframe=true&amp;height=500&amp;width=850' title='修改产品-"
												+ value + "' class='thickbox'>"
												+ value + "</a>";
									}
								}, {
									field : "productShortName",
									title : "产品简称"
								}, {
									field : "typeName",
									title : "产品种类"
								}, {
									field : "companyShortName",
									title : "保险公司"
								}, {
									field : "supName",
									title : "供应商"
								}, {
									field : "productPrice",
									title : "价格",
									formatter : function(value, row, index) {
										return value.toFixed(2);
									}
								}, {
									field : "productSettlePrice",
									title : "结算价格",
									formatter : function(value, row, index) {
										return value.toFixed(2);
									}
								}, {
									field : "productValidTime",
									title : "产品有效期"
								}, {
									field : "productCreatedOn",
									title : "产品创建日期"
								} ] ],
						onLoadSuccess : function(data) {
							tb_Reloadinit();
						}
					});

});
function onSelectBegin(date) {
	$('pbegin').val(date);
}

function onSelectEnd(date) {
	$('pend').val(date);
}

function searchit() {
	var pname = $.trim($("#pname").val());
	var pbegin = $.trim($("input[name='pbegin']").val());
	var pend = $.trim($("input[name='pend']").val());
	var ptype = $.trim($("#ptype").val());
	if (pname == "" && pbegin == "" && pend == "" && ptype == "") {
		alert("请输入查询条件!");
		return;
	}
	var opts = $('#datagrid_list').datagrid("options");
	opts.url = "/product/list.json";
	$('#datagrid_list').datagrid('load', {
		"productName" : pname,
		"productBegin" : pbegin,
		"productEnd" : pend,
		"productType" : ptype
	});
}